package com.wfx.controller;


import com.wfx.entity.PageDTO;
import com.wfx.entity.PageResult;
import com.wfx.entity.Result;
import com.wfx.entity.WxbGoodsTemplate;
import com.wfx.service.IWxbGoodsTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhu
 * @since 2021-01-21
 */
@RestController
@RequestMapping("/template")
@CrossOrigin
@Api(description = "模板管理")
public class WxbGoodsTemplateController {

    @Autowired
    private IWxbGoodsTemplateService iWxbGoodsTemplateService;

    @PostMapping("/search")
    @ApiOperation("分页加条件")
    public PageResult<WxbGoodsTemplate> search(@RequestBody @ApiParam("分页条件") PageDTO<WxbGoodsTemplate> pageDTO){
        if (pageDTO == null) {
            pageDTO.setPage(1);
            pageDTO.setLimit(5);
        }
        return iWxbGoodsTemplateService.search(pageDTO);
    }

    @PostMapping("/addOrUpdate")
    @ApiOperation("添加or修改")
    public Result addOrUpdate(@RequestBody @ApiParam("模板实体") WxbGoodsTemplate wxbGoodsTemplate){
        return iWxbGoodsTemplateService.addOrUpdate(wxbGoodsTemplate);
    }

    @PostMapping("/delTemplates")
    @ApiOperation("批量删除")
    public Result delTemplates(@RequestBody @ApiParam("模板Ids") List<String> templates){
        return iWxbGoodsTemplateService.delTemplates(templates);
    }

    @PostMapping("delOne")
    @ApiOperation("删除")
    public Result delOne(@RequestBody @ApiParam("模板实体") WxbGoodsTemplate wxbGoodsTemplate){
        return iWxbGoodsTemplateService.delOne(wxbGoodsTemplate);
    }

    @PostMapping("/searchAll")
    @ApiOperation("搜索全部")
    public Result searchAll(){
        return iWxbGoodsTemplateService.searchAll();
    }




}
